
--[[

    slimui - Copyright (c) 2011 atom0s, All rights reserved.

    See Copyright notice in slimui.lua
    
]]--

class 'Canvas: Object' { ... };

----------------------------------------------------------------------------------
-- func: Canvas.__init__
-- desc: Constructor called when this object is first created.
----------------------------------------------------------------------------------
function Canvas.__init__( self )
    Object.__init__( self );
end

----------------------------------------------------------------------------------
-- func: Canvas:Create
-- desc: Not implemented. Error on call.
----------------------------------------------------------------------------------
function Canvas:Create( parent )
    slimui:err( 'not implemented' );
end

----------------------------------------------------------------------------------
-- func: Canvas:Bind
-- desc: Binds this canvas object to the given canvas.
----------------------------------------------------------------------------------
function Canvas:Bind( canvas )
    if canvas == nil then
        slimui:err( 'Canvas:Bind - parent canvas cannot be nil' );
    end
    
    local class = object_getClassName( canvas );
    if string.lower( class ) ~= 'tcontrolcanvas' then
        slimui:err( 'Canvas:Bind - cannot bind to objects that are not a canvas!' );
    end
    
    self._object = canvas;
    
    return self;
end

----------------------------------------------------------------------------------
-- func: Canvas:GetBrush
-- desc: Returns the brush associated to this canvas.
----------------------------------------------------------------------------------
function Canvas:GetBrush( )
    return canvas_getBrush( self._object );
end

----------------------------------------------------------------------------------
-- func: Canvas:GetPen
-- desc: Returns the pen associated to this canvas.
----------------------------------------------------------------------------------
function Canvas:GetPen( )
    return canvas_getPen( self._object );
end

----------------------------------------------------------------------------------
-- func: Canvas:GetFont
-- desc: Returns the font associated to this canvas.
----------------------------------------------------------------------------------
function Canvas:GetFont( )
    return canvas_getFont( self._object );
end

----------------------------------------------------------------------------------
-- func: Canvas:GetWidth
-- desc: Returns this canvas' width.
----------------------------------------------------------------------------------
function Canvas:GetWidth( )
    return canvas_getWidth( self._object );
end

----------------------------------------------------------------------------------
-- func: Canvas:GetHeight
-- desc: Returns this canvas' height.
----------------------------------------------------------------------------------
function Canvas:GetHeight( )
    return canvas_getHeight( self._object );
end

----------------------------------------------------------------------------------
-- func: Canvas:GetPenPosition
-- desc: Returns the pen position of this canvas.
----------------------------------------------------------------------------------
function Canvas:GetPenPosition( )
    return canvas_getPenPosition( self._object );
end

----------------------------------------------------------------------------------
-- func: Canvas:SetPenPosition
-- desc: Sets the pen position of this canvas.
----------------------------------------------------------------------------------
function Canvas:SetPenPosition( x, y )
    canvas_setPenPosition( self._object, x, y );
end

----------------------------------------------------------------------------------
-- func: Canvas:Line
-- desc: Draws a line between the given coords.
----------------------------------------------------------------------------------
function Canvas:Line( srcx, srcy, destx, desty )
    canvas_line( self._object, srcx, srcy, destx, desty );
end

----------------------------------------------------------------------------------
-- func: Canvas:LineTo
-- desc: Draws a line to the given point.
----------------------------------------------------------------------------------
function Canvas:LineTo( destx, desty )
    canvas_lineTo( self._object, destx, desty );
end

----------------------------------------------------------------------------------
-- func: Canvas:Rect
-- desc: Draws an outlined rect with the given points.
----------------------------------------------------------------------------------
function Canvas:Rect( x1, y1, x2, y2 )
    canvas_rect( self._object, x1, y1, x2, y2 );
end

----------------------------------------------------------------------------------
-- func: Canvas:FillRect
-- desc: Draws a filled rect with the given points. (No border.)
----------------------------------------------------------------------------------
function Canvas:FillRect( x1, y1, x2, y2 )
    canvas_fillRect( self._object, x1, y1, x2, y2 );
end

----------------------------------------------------------------------------------
-- func: Canvas:TextOut
-- desc: Draws the given text starting at the given point.
----------------------------------------------------------------------------------
function Canvas:TextOut( x, y, text )
    canvas_textOut( self._object, x, y, text );
end

----------------------------------------------------------------------------------
-- func: Canvas:GetTextWidth
-- desc: Returns the given texts width.
----------------------------------------------------------------------------------
function Canvas:GetTextWidth( text )
    canvas_getTextWidth( self._object, text );
end

----------------------------------------------------------------------------------
-- func: Canvas:GetTextHeight
-- desc: Returns the given texts height.
----------------------------------------------------------------------------------
function Canvas:GetTextHeight( text )
    canvas_getTextHeight( self._object, text );
end

----------------------------------------------------------------------------------
-- func: Canvas:GetPixel
-- desc: Returns the color of the pixel at the given point.
----------------------------------------------------------------------------------
function Canvas:GetPixel( x, y )
    canvas_getPixel( self._object, x, y );
end

----------------------------------------------------------------------------------
-- func: Canvas:SetPixel
-- desc: Sets the pixel at the given point to the given color.
----------------------------------------------------------------------------------
function Canvas:SetPixel( x, y, color )
    canvas_setPixel( self._object, x, y, color );
end

----------------------------------------------------------------------------------
-- func: Canvas:FloodFill
-- desc: Unknown
----------------------------------------------------------------------------------
function Canvas:FloodFill( x, y )
    canvas_floodFill( self._object, x, y );
end

----------------------------------------------------------------------------------
-- func: Canvas:Ellipse
-- desc: Draws an ellipse at the given points.
----------------------------------------------------------------------------------
function Canvas:Ellipse( x1, y1, x2, y2 )
    canvas_ellipse( self._object, x1, y1, x2, y2 );
end

----------------------------------------------------------------------------------
-- func: Canvas:GradientFill
-- desc: Draws a gradient at the given points with the specified colors.
----------------------------------------------------------------------------------
function Canvas:GradientFill( x1, y1, x2, y2, startcolor, stopcolor, direction )
    canvas_gradientFill( self._object, x1, y1, x2, y2, startcolor, stopcolor, direction );
end

----------------------------------------------------------------------------------
-- func: Canvas:CopyRect
-- desc: Copies the given rect from this canvas to the given canvas.
----------------------------------------------------------------------------------
function Canvas:CopyRect( destcanvas, srcx1, srcy1, srcx2, srcy1, destx1, desty1, destx2, desty2 )
    canvas_copyRect( destcanvas, destx1, desty1, destx2, desty2, self._object, srcx1, srcy1, srcx2, srcy2 );
end

----------------------------------------------------------------------------------
-- func: Canvas:Draw
-- desc: Draws the given graphic to this canvas.
----------------------------------------------------------------------------------
function Canvas:Draw( x, y, graphic )
    canvas_draw( self._object, x, y, graphic );
end



--[[ Debug information. ]]--------------------------------------------------------
if ( slimui:isdebug() == true ) then
    slimui:msg( '(Control) canvas.lua successfully loaded.' );
end